package mybatis.service.impl;

import java.util.List;

import mybatis.dao.GameDao;
import mybatis.entity.Game;
import mybatis.service.GamesService;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GamesServiceImpl implements GamesService {
	@Autowired
	private GameDao gameDao;
	@Override
	public void addAll(List<Game> list) {
		for(Game game : list) {
			gameDao.add(game);
		}
	}

	@Override
	public List<Game> findNewGames(int currentPage) {
		PageHelper.startPage(currentPage,40);
		List<Game> list = gameDao.findByNew();
		return list;
	}
	
	@Override
	public Game findByNumber(int number) {
		Game game = gameDao.findByNumber(number);
		return game;
	}

	@Override
	public void addGameFeature(int fid, int gid) {
		gameDao.addGameFeature(fid, gid);
	}
	@Override
	public void addGameType(int gid, int tid) {
		gameDao.addGameType(gid, tid);
	}

	@Override
	public void addGameLanguage(int gid, int lid) {
		gameDao.addGameLanguage(gid, lid);
	}
	
	@Override
	public void addSrcs(String src, int gid) {
		gameDao.addSrcs(src, gid);
	}
	
	@Override
	public void addGameVoice(int gid, int vid) {
		gameDao.addGameVoice(gid, vid);
	}

	@Override
	public List<Game> findPageByTid(int tid, int currentPage) {
		// TODO Auto-generated method stub
		System.out.println("tid = " + tid);
		PageHelper.startPage(currentPage,40);
		List<Game> list = gameDao.findAllByTid(tid);
		return list;
	}

	@Override
	public Game findWholeGameById(int id) {
		Game game = gameDao.findWholeGameById(id);
		// TODO Auto-generated method stub
		return game;
	}
}
